package com.lhd.qd.module.system.hospital.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lhd.qd.common.base.ApiResult;
import com.lhd.qd.common.base.BaseController;
import com.lhd.qd.common.base.BasePageQuery;
import com.lhd.qd.module.system.hospital.model.dto.HospitalSaveDTO;
import com.lhd.qd.module.system.hospital.model.vo.HospitalDetailVO;
import com.lhd.qd.module.system.hospital.model.vo.HospitalListVO;
import com.lhd.qd.module.system.hospital.model.vo.HospitalTreeVO;
import com.lhd.qd.module.system.hospital.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "医院")
@RequestMapping("hospital")
@RestController
public class HospitalController extends BaseController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "分页列表", response = HospitalListVO.class)
    @GetMapping
    public ResponseEntity<ApiResult<IPage<HospitalListVO>>> pageHospital(BasePageQuery query) {

        return success(hospitalService.pageHospital(query));
    }

    @ApiOperation(value = "树", response = HospitalTreeVO.class)
    @GetMapping("tree")
    public ResponseEntity<ApiResult<List<HospitalTreeVO>>> getHospitalTree() {

        return success(hospitalService.getHospitalTree());
    }

    @ApiOperation(value = "详情", response = HospitalDetailVO.class)
    @GetMapping("{id}")
    public ResponseEntity<ApiResult<HospitalDetailVO>> getHospitalById(@PathVariable("id") Long id) {

        return success(hospitalService.getHospitalById(id));
    }

    @ApiOperation(value = "新增")
    @PostMapping
    public ResponseEntity<ApiResult> saveHospital(@Validated @RequestBody HospitalSaveDTO saveDTO) {

        return successOrFail(hospitalService.saveHospital(saveDTO));
    }

    @ApiOperation(value = "修改")
    @PutMapping("{id}")
    public ResponseEntity<ApiResult> updateHospitalById(@PathVariable("id") Long id, @Validated @RequestBody HospitalSaveDTO saveDTO) {

        return successOrFail(hospitalService.updateHospitalById(id, saveDTO));
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("{id}")
    public ResponseEntity<ApiResult> removeHospitalById(@PathVariable("id") Long id) {

        return successOrFail(hospitalService.removeHospitalById(id));
    }
}
